This repository was archived by the owner on Jul 14, 2025. It is now read-only.
FIX: Discourse automation reports with parameters#363
Merged
Conversation
Drenmi
commented
Mar 13, 2025
| build_report_post(query, table, attach_csv: opts[:attach_csv], result:) | ||
| end | ||
|
|
||
| private |
Contributor
Author
There was a problem hiding this comment.
Scoping keywords put in the class body only affect instance methods. All methods in this class are class methods and therefore already public.
Drenmi
commented
Mar 13, 2025
Comment on lines
-42
to
-55
| params_hash = {} | ||
|
|
||
| if !params.blank? | ||
| param_key, param_value = [], [] | ||
| params.flatten.each.with_index do |data, i| | ||
| if i % 2 == 0 | ||
| param_key << data | ||
| else | ||
| param_value << data | ||
| end | ||
| end | ||
|
|
||
| params_hash = Hash[param_key.zip(param_value)] | ||
| end |
Contributor
Author
There was a problem hiding this comment.
This chunk is the same as Array#to_h.
451153d to
27a17da
Compare
jjaffeux
approved these changes
Mar 13, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the problem?
When setting up an automation to create a DM or a post with a report on a recurring basis, and using a Data Explorer query that has parameters, we encounter an error.
Why is this happening?
The
.params_to_hashcurrently expects an array of arrays for the parameters, e.g.:but in reality they seem to be arrays of hashes:
How come we only found out now?
We do have tests for the report generator, and we do pass query parameters to it, but 1) we hard-code the parameters as an array of arrays and 2) the parameters aren't in the query used as a fixture.
How does this fix it?
This change makes
ReportGenerator.params_to_hashwork with arrays of hashes. It also preserves the ability to work with nested arrays in case this is used somewhere else.